//
//  EBHUserManager.m
//  EBHDoctor
//
//  Created by 黄德玉 on 2019/11/6.
//  Copyright © 2019 DCloud. All rights reserved.
//

#import "EBHUserManager.h"
#import "MJExtension.h"

#define USER_INFO_KEY @"USER_INFO_KEY"

#define USER_INFO_TARGET_KEY @"USER_INFO_TARGET_KEY"

@implementation EBHUserManager


+ (instancetype)sharedManager{
    static dispatch_once_t onceToken;
    static EBHUserManager * manager;
    dispatch_once(&onceToken, ^{
        manager = [EBHUserManager new];
        manager.targetUserInfo = [EBHTargetUserInfoModel new];
    });
    return manager;
}

- (void)localLogin{
    NSDictionary * dic = [[NSUserDefaults standardUserDefaults] objectForKey:USER_INFO_KEY];
    if (dic) {
        EBHUserInfoModel * model = [EBHUserInfoModel mj_objectWithKeyValues:dic];
        self.userInfo = model;
    }
}

- (void)loginWithUserInfo:(NSDictionary *)dic{
    [[NSUserDefaults standardUserDefaults] setObject:dic forKey:USER_INFO_KEY];
      EBHUserInfoModel * model = [EBHUserInfoModel mj_objectWithKeyValues:dic];
    self.userInfo = model;
}


- (void)updateTargetUserInfo:(NSString *)name avatar:(NSString *)avatar targetId:(NSString *)targetID{
    self.targetUserInfo.name = name;
    self.targetUserInfo.avatar = avatar;
    self.targetUserInfo.id = targetID;
}

@end
